﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Windows.Input;
using System.Windows.Data;
using System.Threading.Tasks;
using System.Windows;
using System.Globalization;
using System.Windows.Navigation;

namespace Molia.Premiere
{
    class WindowClose : ICommand
    {
        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public void Execute(object parameter)
        {
            if (parameter is Window)
            {
                (parameter as Window).Close();
            }
        }
    }
    class WindowMin : ICommand
    {
        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public void Execute(object parameter)
        {
            if (parameter is Window)
            {
                (parameter as Window).WindowState = WindowState.Minimized;
            }
        }
    }
    class WindowMax : ICommand
    {
        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public void Execute(object parameter)
        {
            if (parameter is Window)
            {
                (parameter as Window).WindowState =
                    (parameter as Window).WindowState == WindowState.Maximized
                    ? WindowState.Normal :
                    WindowState.Maximized;
            }
        }
    }
    class MaxButtonContent : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var v = (WindowState) value;
            if (v == WindowState.Maximized)
            {
                return "";
            }
            else
            {
                return "";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ' ';
        }
    }
    class MaxEnable : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var isen = (ResizeMode) value;
            if(isen== ResizeMode.CanResize||isen== ResizeMode.CanResizeWithGrip)
            {
                return Visibility.Visible;
            }
            else
            {
                return Visibility.Collapsed;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {

        public static ICommand WindowClose { get; set; } = new WindowClose();
        public static ICommand WindowMin { get; set; } = new WindowMin();
        public static ICommand WindowMax { get; set; } = new WindowMax();
        public static IValueConverter ButtonContent { get; set; } = new MaxButtonContent();
        public static IValueConverter ButtonEnable { get; set; } = new MaxEnable();
        protected override void OnLoadCompleted(NavigationEventArgs e)
        {
            base.OnLoadCompleted(e);
            Static.GlobalField.ThemeProvider.Default(Application.Current.MainWindow);
        }
    }
}